#include "Bullet.h"
#include "Field.h"
#include "Object.h"

#include <fstream>

void Bullet::update( int updateNumber ){
    if( updateNumber == getLastUpdate() ) return;
    else setLastUpdate( updateNumber );
    for( int i = 0; i < speed; i++ ){
        if( !(getField()->move( direction, 1, this ) ) ){
            //if( getField()->objectAt( getX() + 1, getY() + 1 )  )
            getField()->objectAt( direction, 1, getField()->
                                  objectAt( getX(), getY() ) )->damage( DMGVALUE );
            return getField()->destroy( getX(), getY() );
        }
    }
    paint();
}

void Bullet::save( ofstream* save, ofstream* config ){
    (*save) << '*';
    (*config) << 'B' << int( getDirection() ) << endl
              << getSpeed() << endl;
}
